﻿using FriendAnalyzer.Business.Model;
using FriendAnalyzer.Infrastructure.Facebook.Model;
using System.Collections.Generic;
using System.Linq;

namespace FriendAnalyzer.Business.FacebookFilter
{
    public class GroupAggregationStrategy : BaseAggregationStrategy
    {
        public override List<AggregateResult> AggregateData(List<FacebookUser> users)
        {
            var events = from user in users
                         from grp in user.Groups
                         group grp by grp.GroupID into grp
                         select new AggregateCriteria
                         {
                             CriteriaID = grp.Key,
                             Matches = grp.Select(i => i.MemberID).Distinct().OrderBy(i => i).ToList(),
                         };

            return ParseCriteriaList(events);
        }
    }
}
